// 冒泡
function f1(arr) {
  for (let i = 0; i < arr.length - 1; i++) {
    for (let j = 0; j < arr.length - 1 - i; j++) {
      if (arr[j] > arr[j + 1]) {
        const ls = arr[j]
        arr[j] = arr[j + 1]
        arr[j + 1] = ls
      }
    }
  }
}

// 选择
function f1(arr) {
  for (let i = 0; i < arr.length - 1; i++) {
    let lsIndex = i
    for (let j = i; j < arr.length; j++) {
      if (arr[lsIndex] > arr[j]) {
        lsIndex = j
      }
    }
    if (lsIndex !== i) {
      const ns = arr[i]
      arr[i] = arr[lsIndex]
      arr[lsIndex] = ns
    }
  }
}

// 快排
function f1(arr) {
  if (arr.length <= 1) return arr
  const pivot = arr.splice(Math.floor(arr.length / 2), 1)[0]
  const left = []
  const right = []
  for (let i = 0; i < arr.length; i++) {
    if (arr[i] < pivot) {
      left.push(arr[i])
    } else {
      right.push(arr[i])
    }
  }
  return [...f1(left), pivot, ...f1(right)]
}